<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <title>已选课程</title>
</head>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<link rel="stylesheet" href="../css/student.css">
<link rel="stylesheet" href="../css/header.css">

<body style="background: url('../img/bg-min.jpg');background-size: cover;">
    <div id="app5">
        <div class="header">
            <div class="logo">
                <h1>学生课程管理系统</h1>
            </div>
            <el-menu class="el-menu-nav" mode="horizontal" background-color="#545c64" text-color="#fff"
                active-text-color="#ffd04b" router>
                <el-submenu index="1">
                    <template slot="title">个人信息</template>
                    <el-menu-item @click="toMember">{{userName}}</el-menu-item>
                </el-submenu>
            </el-menu>
            <div class="line"></div>
        </div>
        <div class="main">
            <div class="leftMenu" style="width: 145px;">
                <el-row class="tac" style="width: 145px;">
                    <el-menu default-active="2" class="el-menu-vertical-demo" background-color="#545c64"
                        text-color="#fff" active-text-color="#ffd04b">
                        <el-menu-item index="1" @click="selectCurseList">
                            <span slot="title">选课列表</span>
                        </el-menu-item>
                        <el-menu-item index="2" @click="tostudentSelectedSubject">
                            <span slot="title">已选列表</span>
                        </el-menu-item>
                        <el-menu-item index="3" @click="toMySubject">
                            <span slot="title">课程表</span>
                        </el-menu-item>
                        <el-menu-item index="4" @click="toStudentInfo">
                            <span slot="title">个人信息</span>
                        </el-menu-item>
                    </el-menu>
                </el-row>
            </div>
            <div class="rightMenu subject-state">
                <el-table :data="tableData" style="width: 100%">
                    <el-table-column prop="subject_name" label="课程名称">
                    </el-table-column>
                    <el-table-column label="操作" width="350">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="detailSubject(scope.$index, scope.row)">详情
                            </el-button>
                            <el-button size="mini" type="danger" @click="deleteSubject(scope.$index, scope.row)">删除
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <!--课程详情-->
            <el-dialog title="课程详情" :visible.sync="dialogFormVisible">
                <el-table :data="form" style="width: 100%">
                    <el-table-column prop="subject_name" label="课程名称">
                    </el-table-column>
                    <el-table-column prop="teacher_name" label="老师">
                    </el-table-column>
                    <el-table-column prop="date" label="日期">
                    </el-table-column>
                    <el-table-column prop="time_start" label="开始时间">
                    </el-table-column>
                    <el-table-column prop="time_end" label="结束时间">
                    </el-table-column>
                </el-table>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>

</body>
<script>
    var app5 = new Vue({
        el: '#app5',
        data: {
            url: 'http://127.0.0.1:8080',
            userName: "",
            tableData: [],
            formLabelWidth: '120px',
            form: [],
            dialogFormVisible: false
        },
        mounted: function () {
            this.getSubjectList();
            this.userName = window.localStorage.getItem("userName")
        },
        methods: {
            //学生管理
            toStudent: function () {
                window.location.href = "studentManage.html"
            },
            toTeacher: function () { window.location.href = "teacherManage.html" },
            toSubject: function () { window.location.href = "subjectManage.html" },
            toInfo: function () { window.location.href = "studentManage.html" },
            toMember: function () {
                window.location.href = "studentInfo.html"
            },
            //查询课程列表
            getSubjectList: function () {
                var _this = this;
                axios.get(this.url + '/coursestudent/query', {
                    params: {
                        student_id: window.localStorage.getItem("creator")
                    }
                }).then(function (res) {
                    if (res.data.msg == 'success') {
                        res = res.data;
                        _this.tableData = res.obj
                    }

                })
            },
            //打开新增窗口
            addSubject: function () {
                this.dialogFormVisible = true
            },
            //删除
            deleteSubject: function (index, row) {
                var _this = this;
                this.$confirm('是否确定删除此信息', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.post(this.url + '/coursestudent/delete?id='+ row.id).then(function (res) {
                        if (res.data.msg == 'success') {
                            res = res.data;
                            _this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            _this.getSubjectList()
                        } else {
                            _this.$message.error('删除失败');
                        }
                    })
                }).catch(() => {
                    _this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //查询课程详情
            detailSubject: function (index, row) {
                var _this = this;
                axios.get(this.url + '/subjectdetail/query?subject_id=' + row.subject_id)
                    .then(function (res) {
                        if (res.data.msg == 'success') {
                            res = res.data;
                            _this.form = res.obj;
                            _this.dialogFormVisible = true
                        }
                    })
            },
            selectCurseList: function () {
                window.location.href = "selectCurseList.html"
            },
            toMySubject: function () {
                window.location.href = "mySubject.html"
            },
            tostudentSelectedSubject: function () {
                window.location.href = "studentSelectedSubject.html"
            },
            toStudentInfo: function () {
                window.location.href = "studentInfo.html"
            },
            //字段校验
            judgeRule: function () {
                if (!this.form.name) return this.$message({
                    message: '请输入课程名称',
                    type: 'warning'
                })
                if (!this.form.teacher_name) return this.$message({
                    message: '请输入老师姓名',
                    type: 'warning'
                })
                if (!this.form.start_date) return this.$message({
                    message: '请输入开始时间',
                    type: 'warning'
                })
                if (!this.form.end_date) return this.$message({
                    message: '请输入结束时间',
                    type: 'warning'
                })
            }
        }
    });
</script>

</html>
